#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

bool row[10][10];
bool col[10][10];
bool grid[3][3][10];
vector<vector<char>> board;
bool ret = true;

void dfs(int pos)
{
    if (pos == board.size())
        return;

    for (int i = 0; i < 9; ++i)
    {
        if (board[pos][i] != '.')
        {
            int num = board[pos][i] - '0';

            if (row[pos][num] == false)
            {
                row[pos][num] = true;
            }
            else
            {
                ret = false;
                return;
            }
            if (col[i][num] == false)
            {
                col[i][num] = true;
            }
            else {
                ret = false;
                return;
            }
            if (grid[pos / 3][i / 3][num] == false)
            {
                grid[pos / 3][i / 3][num] = true;
            }
            else {
                ret = false;
                return;
            }
        }
    }
    dfs(pos + 1);
}

bool isValidSudoku(const vector<vector<char>>& b) {
    board = b;

    dfs(0);

    return ret;
}

int main()
{
    isValidSudoku();
	return 0;
}